<?php
require_once("server/sesion.php");

$sesion = new sesion();
$usuario = $sesion->get("ses");
if ($usuario == false) {
    header("Location: index.php");
} else if ($usuario != 1) {
    header("Location: index.php");
} else {
    //Conexion de pruebas
//$link = mysql_connect("localhost", "root", ""); 
//mysql_select_db("apptite", $link); 
    $link = mysql_connect("localhost", "root", "");
    mysql_select_db("apptite", $link);
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>Cheff @ppetite v1.0</title>        
            <link rel="stylesheet"  href="css/themes/default/jquery.mobile-1.3.1.min.css">
            <link rel="stylesheet"  href="css/themes/default/jquery.mobile.structure-1.3.1.min.css">

        </head>
        <body>
            <section id="pageUsuarios" data-role="page" data-theme="b">
                <header data-role="header" data-theme="b">
                    <a href="administrador.php" data-icon="back" data-iconpos="notext">Volver</a>
                    <h1>Usuarios</h1>
                    <a data-rel="dialog" href="ajustes.php" class="ui-btn-right" data-icon="grid" data-iconpos="notext">Ajustes</a>
                </header>
                <article data-role="content" data-theme="b">
                    <center>
                        <form method="post" action="actualizarUsuario.php">
                            <div id="busqueda">
                                <input type="text" id="q" name="q" value="" placeholder="Digite el numero de documento del usuario" />
                            </div>
                            <?php
                            $resultProducto = mysql_query("SELECT idusuario, nroDocumento, nombre, apellido, genero, direccion, telefono, email, clave, idRol, idsede, indHabilitado FROM usuario order by idusuario desc", $link);
                            echo "<table border = '0' class='table-hover table-striped' id='latabla'> \n";
                            echo "<tr>
                                <td></td>
					   		 <td>DOCUMENTO</td>
							 <td>NOMBRES</td>
							 <td>EMAIL</td>
							 <td>EDITAR</td>
							 </tr> \n";
                            $i = 0;
                            while ($row = mysql_fetch_row($resultProducto)) {
                                echo "<tr>
                                    <td><input type='hidden' id='idusuario' name='idusuario[$i]' value='" . $row[0] . "' style='width: 50px;'/></td>
						  <td><p id='documento' name='documento[$i]' >" . $row[1] . "<p/></td>
						  <td><input type='text' id='nombre' name='nombre[$i]' value='" . $row[2] . " - " . $row[3] . "'/></td>
						  <td><input type='text' id='email' name='email[$i]' value='" . $row[7] . "' /></td>
						  <td> <input type='submit'  name='seleccion[$i]' id='btnActualizar" . $row[0] . "' class='ui-btn-right' data-icon='grid' data-iconpos='notext'></td>
								</tr>\n";
                                $i++;
                            }
                            echo "</table> \n";
                            ?> 
                        </form>
                    </center>

                    <a data-rel="page" onclick="$.mobile.changePage('creacionusuario.php');" data-role="button">Crear Usuario</a>  
                </article>
            </section>

            <!-- aquí se cargan los scripts -->


            <script src="js/static/jquery.js"></script>
            <script src="js/static/jquery.mobile-1.3.1.min.js"></script> 
            <script src="js/jquery.uitablefilter.js" type="text/javascript"></script>
            <script language="javascript">
                        $(function() {
                            theTable = $("#latabla");
                            $("#q").keyup(function() {
                                $.uiTableFilter(theTable, this.value);
                            });
                        });
            </script>

        </body>
    </html>
    <?php
}
?>

